using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{

    public class CLSMAECLIP : ObservableObject
    {
        MDOgeneral mod = new MDOgeneral();

        #region Metodos 

        public List<CLSMAECLIP> listaCliente()
        {
            try
            {
                string query = "select Q.CODCLI_CLI,concat(concat(Q.CODCLI_CLI, ' - '), Q.NOMCLI_CLI) as NOMCLI_CLI,Q.NOMREP_CLI,Q.CONTAC_CLI,Q.DIRCLI_CLI,(select NOMCIU_CIU from MAECIUP where CODCIU_CIU=CODCIU_CLI) as CODCIU_CLI,Q.NITCLI_CLI,Q.TEL1CLI_CLI,Q.TEL2CLI_CLI,Q.FAXCLI_CLI,Q.PLAZO_CLI,Q.APLRTE_CLI,Q.CLICOM_CLI,Q.TIPO_CLI,(select CODLIS_CLI from LISPREP where CODLIS_PRE=CODLIS_CLI and TIPLIS_PRE='P') as CODLIS_CLI, (select CODLIS_CLI from LISPREP where CODLIS_PRE=CODLISREP_CLI and TIPLIS_PRE='P') as CODLISREP_CLI,Q.EMAIL_CLI,(select NOMCLI_CLI from MAECLIP  where CODCLI_CLI=Q.CLIPPAL_CLI) as CLIPPAL_CLI,Q.ESTADO_CLI, Q.dctcli_cli, Q.CLIINTERNO_CLI from MAECLIP Q order by q.nomcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();
                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString(),
                        NOMREP_CLI = r["NOMREP_CLI"].ToString(),
                        CONTAC_CLI = r["CONTAC_CLI"].ToString(),
                        DIRCLI_CLI = r["DIRCLI_CLI"].ToString(),
                        CODCIU_CLI = r["CODCIU_CLI"].ToString(),
                        NITCLI_CLI = r["NITCLI_CLI"].ToString(),
                        TEL1CLI_CLI = r["TEL1CLI_CLI"].ToString(),
                        TEL2CLI_CLI = r["TEL2CLI_CLI"].ToString(),
                        FAXCLI_CLI = r["FAXCLI_CLI"].ToString(),
                        PLAZO_CLI = r["PLAZO_CLI"].ToString(),
                        APLRTE_CLI = r["APLRTE_CLI"].ToString().Equals("S")?"Si":"No",
                        CLICOM_CLI = r["CLICOM_CLI"].ToString().Equals("S") ? "Si" : "No",
                        TIPO_CLI = r["TIPO_CLI"].ToString().Equals("P")?"Principal":"Secundario",
                        CODLIS_CLI = r["CODLIS_CLI"].ToString(),
                        CODLISREP_CLI = r["CODLISREP_CLI"].ToString(),
                        EMAIL_CLI = r["EMAIL_CLI"].ToString(),
                        CLIPPAL_CLI = r["CLIPPAL_CLI"].ToString(),
                        ESTADO_CLI = r["ESTADO_CLI"].ToString().Equals("A")?"Activo":"Inactivo",
                        DCTCLI_CLI = Convert.ToDouble(r["DCTCLI_CLI"]),
                        CLIINTERNO_CLI = r["CLIINTERNO_CLI"].ToString().Equals("S")?"Si":"No"
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClientesInternos()
        {
            try
            {
                string query = "select Q.CODCLI_CLI,concat(concat(Q.CODCLI_CLI, ' - '), Q.NOMCLI_CLI) as NOMCLI_CLI,Q.NOMREP_CLI,Q.CONTAC_CLI,Q.DIRCLI_CLI,(select NOMCIU_CIU from MAECIUP where CODCIU_CIU=CODCIU_CLI) as CODCIU_CLI,Q.NITCLI_CLI,Q.TEL1CLI_CLI,Q.TEL2CLI_CLI,Q.FAXCLI_CLI,Q.PLAZO_CLI,Q.APLRTE_CLI,Q.CLICOM_CLI,Q.TIPO_CLI,(select CODLIS_CLI from LISPREP where CODLIS_PRE=CODLIS_CLI and TIPLIS_PRE='P') as CODLIS_CLI, (select CODLIS_CLI from LISPREP where CODLIS_PRE=CODLISREP_CLI and TIPLIS_PRE='P') as CODLISREP_CLI, Q.EMAIL_CLI,(select NOMCLI_CLI from MAECLIP  where CODCLI_CLI=Q.CLIPPAL_CLI) as CLIPPAL_CLI,Q.ESTADO_CLI, Q.dctcli_cli, Q.CLIINTERNO_CLI from MAECLIP Q where Q.CLIINTERNO_CLI = 'S' order by q.nomcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();
                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString(),
                        NOMREP_CLI = r["NOMREP_CLI"].ToString(),
                        CONTAC_CLI = r["CONTAC_CLI"].ToString(),
                        DIRCLI_CLI = r["DIRCLI_CLI"].ToString(),
                        CODCIU_CLI = r["CODCIU_CLI"].ToString(),
                        NITCLI_CLI = r["NITCLI_CLI"].ToString(),
                        TEL1CLI_CLI = r["TEL1CLI_CLI"].ToString(),
                        TEL2CLI_CLI = r["TEL2CLI_CLI"].ToString(),
                        FAXCLI_CLI = r["FAXCLI_CLI"].ToString(),
                        PLAZO_CLI = r["PLAZO_CLI"].ToString(),
                        APLRTE_CLI = r["APLRTE_CLI"].ToString().Equals("S") ? "Si" : "No",
                        CLICOM_CLI = r["CLICOM_CLI"].ToString().Equals("S") ? "Si" : "No",
                        TIPO_CLI = r["TIPO_CLI"].ToString().Equals("P") ? "Principal" : "Secundario",
                        CODLIS_CLI = r["CODLIS_CLI"].ToString(),
                        CODLISREP_CLI = r["CODLISREP_CLI"].ToString(),
                        EMAIL_CLI = r["EMAIL_CLI"].ToString(),
                        CLIPPAL_CLI = r["CLIPPAL_CLI"].ToString(),
                        ESTADO_CLI = r["ESTADO_CLI"].ToString().Equals("A") ? "Activo" : "Inactivo",
                        DCTCLI_CLI = Convert.ToDouble(r["DCTCLI_CLI"]),
                        CLIINTERNO_CLI = r["CLIINTERNO_CLI"].ToString().Equals("S") ? "Si" : "No"
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClienteReparacionesListas()
        {
            try
            {
                string query = "select distinct B.codcli_cli, concat(concat(B.CODCLI_CLI, ' - '), B.NOMCLI_CLI) as NOMCLI_CLI from encrepp a inner join maeclip b on a.codcli_erp=b.codcli_cli where estado_erp = 'R' order by B.codcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();

                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString()
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClienteReparacionesaEntregar()
        {
            try
            {
                string query = "select distinct B.codcli_cli, concat(concat(B.CODCLI_CLI, ' - '), B.NOMCLI_CLI) as NOMCLI_CLI from encrepp a inner join maeclip b on a.codcli_erp=b.codcli_cli where estado_erp = 'R' order by B.codcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();

                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString()
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClienteReparaciones()
        {
            try
            {
                string query = "select distinct B.codcli_cli, concat(concat(B.CODCLI_CLI, ' - '), B.NOMCLI_CLI) as NOMCLI_CLI from encrepp a inner join maeclip b on a.codcli_erp=b.codcli_cli order by B.codcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();

                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString()
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClienteGarantias()
        {
            try
            {
                string query = "select distinct B.codcli_cli, concat(concat(B.CODCLI_CLI, ' - '), B.NOMCLI_CLI) as NOMCLI_CLI from reppendp a left join maeclip b on a.codcli_rpn=b.codcli_cli order by B.codcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();

                lisCliente.Add(new CLSMAECLIP
                {
                    CODCLI_CLI = "ZZZ",
                    NOMCLI_CLI = "Todos"
                });

                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString()
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaClienteFacturas()
        {
            try
            {
                string query = "select distinct B.codcli_cli, concat(concat(B.CODCLI_CLI, ' - '), B.NOMCLI_CLI) as NOMCLI_CLI from encfacp a left join maeclip b on a.codcli_efa=b.codcli_cli order by B.codcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();

                lisCliente.Add(new CLSMAECLIP
                {
                    CODCLI_CLI = "ZZZ",
                    NOMCLI_CLI = "Todos"
                });

                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString()
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listadodeClientes()
        {
            try
            {
                string query = "select Q.CODCLI_CLI,Q.NOMCLI_CLI,Q.NOMREP_CLI,Q.CONTAC_CLI,Q.DIRCLI_CLI,(select NOMCIU_CIU from MAECIUP where CODCIU_CIU=CODCIU_CLI) as CODCIU_CLI,Q.NITCLI_CLI,Q.TEL1CLI_CLI,Q.TEL2CLI_CLI,Q.FAXCLI_CLI,Q.PLAZO_CLI,Q.APLRTE_CLI,Q.CLICOM_CLI,Q.TIPO_CLI,(select CODLIS_PRE from LISPREP where CODLIS_PRE=CODLIS_CLI and TIPLIS_PRE='P') as CODLIS_CLI, (select CODLIS_PRE from LISPREP where CODLIS_PRE=CODLISREP_CLI and TIPLIS_PRE='P') as CODLISREP_CLI, Q.EMAIL_CLI,(select NOMCLI_CLI from MAECLIP  where CODCLI_CLI=Q.CLIPPAL_CLI) as CLIPPAL_CLI,Q.ESTADO_CLI, Q.dctcli_cli, Q.CLIINTERNO_CLI from MAECLIP Q order by q.nomcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();
                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString().Trim(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString(),
                        NOMREP_CLI = r["NOMREP_CLI"].ToString(),
                        CONTAC_CLI = r["CONTAC_CLI"].ToString(),
                        DIRCLI_CLI = r["DIRCLI_CLI"].ToString(),
                        CODCIU_CLI = r["CODCIU_CLI"].ToString(),
                        NITCLI_CLI = r["NITCLI_CLI"].ToString(),
                        TEL1CLI_CLI = r["TEL1CLI_CLI"].ToString(),
                        TEL2CLI_CLI = r["TEL2CLI_CLI"].ToString(),
                        FAXCLI_CLI = r["FAXCLI_CLI"].ToString(),
                        PLAZO_CLI = r["PLAZO_CLI"].ToString(),
                        APLRTE_CLI = r["APLRTE_CLI"].ToString().Equals("S") ? "Si" : "No",
                        CLICOM_CLI = r["CLICOM_CLI"].ToString().Equals("S") ? "Si" : "No",
                        TIPO_CLI = r["TIPO_CLI"].ToString().Equals("P") ? "Principal" : "Secundario",
                        CODLIS_CLI = r["CODLIS_CLI"].ToString(),
                        CODLISREP_CLI = r["CODLISREP_CLI"].ToString(),
                        EMAIL_CLI = r["EMAIL_CLI"].ToString(),
                        CLIPPAL_CLI = r["CLIPPAL_CLI"].ToString(),
                        ESTADO_CLI = r["ESTADO_CLI"].ToString().Equals("A") ? "Activo" : "Inactivo",
                        DCTCLI_CLI = Convert.ToDouble(r["DCTCLI_CLI"]),
                        CLIINTERNO_CLI = r["CLIINTERNO_CLI"].ToString().Equals("S") ? "Si" : "No"
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        public List<CLSMAECLIP> listaSubCliente()
        {
            try
            {
                string query = "select Q.CODCLI_CLI,Q.NOMCLI_CLI,Q.NOMREP_CLI,Q.CONTAC_CLI,Q.DIRCLI_CLI,(select NOMCIU_CIU from MAECIUP where CODCIU_CIU=CODCIU_CLI) as CODCIU_CLI,Q.NITCLI_CLI,Q.TEL1CLI_CLI,Q.TEL2CLI_CLI,Q.FAXCLI_CLI,Q.PLAZO_CLI,Q.APLRTE_CLI,Q.CLICOM_CLI,Q.TIPO_CLI,(select NOMLIS_PRE from LISPREP where CODLIS_PRE=CODLIS_CLI and TIPLIS_PRE='C') as CODLIS_CLI, (select NOMLIS_PRE from LISPREP where CODLIS_PRE=CODLISREP_CLI and TIPLIS_PRE='C') as CODLISREP_CLI,Q.EMAIL_CLI,(select NOMCLI_CLI from MAECLIP  where CODCLI_CLI=Q.CLIPPAL_CLI) as CLIPPAL_CLI,Q.ESTADO_CLI,Q.DCTCLI_CLI, Q.CLIINTERNO_CLI from MAECLIP Q where Q.CLIPPAL_CLI='" + CODCLI_CLI + "' order by q.nomcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();
                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString(),
                        NOMCLI_CLI = r["CODCLI_CLI"].ToString() + " - " + r["NOMCLI_CLI"].ToString(),
                        NOMREP_CLI = r["NOMREP_CLI"].ToString(),
                        CONTAC_CLI = r["CONTAC_CLI"].ToString(),
                        DIRCLI_CLI = r["DIRCLI_CLI"].ToString(),
                        CODCIU_CLI = r["CODCIU_CLI"].ToString(),
                        NITCLI_CLI = r["NITCLI_CLI"].ToString(),
                        TEL1CLI_CLI = r["TEL1CLI_CLI"].ToString(),
                        TEL2CLI_CLI = r["TEL2CLI_CLI"].ToString(),
                        FAXCLI_CLI = r["FAXCLI_CLI"].ToString(),
                        PLAZO_CLI = r["PLAZO_CLI"].ToString(),
                        APLRTE_CLI = r["APLRTE_CLI"].ToString().Equals("S") ? "Si" : "No",
                        CLICOM_CLI = r["CLICOM_CLI"].ToString().Equals("S") ? "Si" : "No",
                        TIPO_CLI = r["TIPO_CLI"].ToString().Equals("P") ? "Principal" : "Secundario",
                        CODLIS_CLI = r["CODLIS_CLI"].ToString(),
                        CODLISREP_CLI = r["CODLISREP_CLI"].ToString(),
                        EMAIL_CLI = r["EMAIL_CLI"].ToString(),
                        CLIPPAL_CLI = r["CLIPPAL_CLI"].ToString(),
                        ESTADO_CLI = r["ESTADO_CLI"].ToString().Equals("A") ? "Activo" : "Inactivo",
                        DCTCLI_CLI = Convert.ToDouble(r["DCTCLI_CLI"]),
                        CLIINTERNO_CLI = r["CLIINTERNO_CLI"].ToString().Equals("S") ? "Si" : "No"
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }


        public void consultar()
        {
            try
            {
                string query = "select CODCLI_CLI,NOMCLI_CLI,NOMREP_CLI,CONTAC_CLI,DIRCLI_CLI,CODCIU_CLI,NITCLI_CLI,TEL1CLI_CLI,TEL2CLI_CLI,FAXCLI_CLI,PLAZO_CLI,APLRTE_CLI,CLICOM_CLI,TIPO_CLI,CODLIS_CLI,CODLISREP_CLI,EMAIL_CLI,CLIPPAL_CLI,ESTADO_CLI,DCTCLI_CLI,CLIINTERNO_CLI from MAECLIP where (CODCLI_CLI='" + CODCLI_CLI + "') order by nomcli_cli";
                DataTable val = mod.consulta(query);
                if (val.Rows.Count > 0)
                {
                    this.CODCLI_CLI = val.Rows[0]["CODCLI_CLI"].ToString();
                    this.NOMCLI_CLI = val.Rows[0]["NOMCLI_CLI"].ToString();
                    this.NOMREP_CLI = val.Rows[0]["NOMREP_CLI"].ToString();
                    this.CONTAC_CLI = val.Rows[0]["CONTAC_CLI"].ToString();
                    this.DIRCLI_CLI = val.Rows[0]["DIRCLI_CLI"].ToString();
                    this.CODCIU_CLI = val.Rows[0]["CODCIU_CLI"].ToString();
                    this.NITCLI_CLI = val.Rows[0]["NITCLI_CLI"].ToString();
                    this.TEL1CLI_CLI = val.Rows[0]["TEL1CLI_CLI"].ToString();
                    this.TEL2CLI_CLI = val.Rows[0]["TEL2CLI_CLI"].ToString();
                    this.FAXCLI_CLI = val.Rows[0]["FAXCLI_CLI"].ToString();
                    this.PLAZO_CLI = val.Rows[0]["PLAZO_CLI"].ToString();
                    this.APLRTE_CLI = val.Rows[0]["APLRTE_CLI"].ToString();
                    this.CLICOM_CLI = val.Rows[0]["CLICOM_CLI"].ToString();
                    this.TIPO_CLI = val.Rows[0]["TIPO_CLI"].ToString();
                    this.CODLIS_CLI = val.Rows[0]["CODLIS_CLI"].ToString();
                    this.CODLISREP_CLI = val.Rows[0]["CODLISREP_CLI"].ToString();
                    this.EMAIL_CLI = val.Rows[0]["EMAIL_CLI"].ToString();
                    this.CLIPPAL_CLI = val.Rows[0]["CLIPPAL_CLI"].ToString();
                    this.ESTADO_CLI = val.Rows[0]["ESTADO_CLI"].ToString();
                    this.DCTCLI_CLI = Convert.ToDouble(val.Rows[0]["DCTCLI_CLI"]);
                    this.CLIINTERNO_CLI = val.Rows[0]["CLIINTERNO_CLI"].ToString();
                    EXISTE = true;
                    CAMBIO = false;
                }
                else
                {
                    EXISTE = false;
                }

            }
            catch (Exception e) { throw e; }
        }

        public DataTable ClientesSec()
        {
            try
            {
                string query = "select codcli_cli, concat(concat(CODCLI_CLI, ' - '), NOMCLI_CLI) as NOMCLI_CLI from maeclip where clippal_cli='" + CODCLI_CLI + "' order by nomcli_cli";
                return mod.consulta(query);
            }
            catch (Exception e) { throw e; }
        }

        public int actualizar()
        {
            try
            {
                if (String.IsNullOrEmpty(APLRTE_CLI) == true) { APLRTE_CLI = "N"; }

                string query = "update MAECLIP set NOMCLI_CLI='" + NOMCLI_CLI + "',NOMREP_CLI='" + NOMREP_CLI + "',CONTAC_CLI='" + CONTAC_CLI + "',DIRCLI_CLI='" + DIRCLI_CLI + "',CODCIU_CLI='" + CODCIU_CLI + "',NITCLI_CLI='" + NITCLI_CLI + "',TEL1CLI_CLI='" + TEL1CLI_CLI + "',TEL2CLI_CLI='" + TEL2CLI_CLI + "',FAXCLI_CLI='" + FAXCLI_CLI + "',PLAZO_CLI=" + PLAZO_CLI + ",APLRTE_CLI='" + APLRTE_CLI + "', CLICOM_CLI='" + CLICOM_CLI + "',TIPO_CLI='" + TIPO_CLI + "',CODLIS_CLI='" + CODLIS_CLI + "',CODLISREP_CLI='" + CODLISREP_CLI + "',EMAIL_CLI='" + EMAIL_CLI + "',CLIPPAL_CLI='" + CLIPPAL_CLI + "',ESTADO_CLI='" + ESTADO_CLI + "',DCTCLI_CLI=" + DCTCLI_CLI + " , CLIINTERNO_CLI='" + CLIINTERNO_CLI + "' where (CODCLI_CLI='" + CODCLI_CLI + "')";
                return mod.comando(query);
            }
            catch (Exception e) { throw e; }
        }
        public int insertar()
        {
            try
            {
                if (String.IsNullOrEmpty(FAXCLI_CLI) == true)
                {
                    FAXCLI_CLI = "0";
                }

                if (String.IsNullOrEmpty(APLRTE_CLI) == true) { APLRTE_CLI = "N"; }

                string query = "insert into MAECLIP (CODCLI_CLI,NOMCLI_CLI,NOMREP_CLI,CONTAC_CLI,DIRCLI_CLI,CODCIU_CLI,NITCLI_CLI,TEL1CLI_CLI,TEL2CLI_CLI,FAXCLI_CLI,PLAZO_CLI,APLRTE_CLI,CLICOM_CLI,TIPO_CLI,CODLIS_CLI,CODLISREP_CLI,EMAIL_CLI,CLIPPAL_CLI,ESTADO_CLI,DCTCLI_CLI,CLIINTERNO_CLI) values ('" + CODCLI_CLI + "','" + NOMCLI_CLI + "','" + NOMREP_CLI + "','" + CONTAC_CLI + "','" + DIRCLI_CLI + "','" + CODCIU_CLI + "','" + NITCLI_CLI + "','" + TEL1CLI_CLI + "','" + TEL2CLI_CLI + "','" + FAXCLI_CLI + "'," + PLAZO_CLI + ",'" + APLRTE_CLI + "','" + CLICOM_CLI + "','" + TIPO_CLI + "','" + CODLIS_CLI + "', '" + CODLISREP_CLI + "','" + EMAIL_CLI + "','" + CLIPPAL_CLI + "','" + ESTADO_CLI + "'," + DCTCLI_CLI + ",'" + CLIINTERNO_CLI + "')";
                return mod.comando(query);
            }
            catch (Exception e) { throw e; }
        }
        public int eliminar()
        {
            try
            {
                string query = "delete from MAECLIP where (CODCLI_CLI='" + CODCLI_CLI + "')";
                return mod.comando(query);
            }
            catch (Exception e) { throw e; }
        }
        public List<CLSMAECLIP> listarPpal()
        {
            try
            {
                string query = "select CODCLI_CLI, concat(concat(CODCLI_CLI, ' - '), NOMCLI_CLI) as NOMCLI_CLI from MAECLIP where TIPO_CLI='P' order by nomcli_cli";
                DataTable val = mod.consulta(query);
                List<CLSMAECLIP> lisCliente = new List<CLSMAECLIP>();
                foreach (DataRow r in val.Rows)
                {
                    lisCliente.Add(new CLSMAECLIP
                    {
                        CODCLI_CLI = r["CODCLI_CLI"].ToString(),
                        NOMCLI_CLI = r["NOMCLI_CLI"].ToString(),
                    });
                }
                return lisCliente;
            }
            catch (Exception e) { throw e; }
        }

        #endregion

        #region Metodos basicos tabla
        public Boolean existe() 
        {
            try
            {
                string query="select  coalesce(count(CODCLI_CLI),0) from MAECLIP where (CODCLI_CLI='"+CODCLI_CLI+"')";
                DataTable val = mod.consulta(query);
                if (val.Rows[0][0].ToString().Equals("0"))
                {
                    return false;
                }
                return true;
            } catch (Exception e) { throw e; }
        }
        public DataTable buscar() 
        {
            try
            {
                string query="select CODCLI_CLI as Codigo,NOMCLI_CLI as Nombre from  MAECLIP where ";
                if(NOMCLI_CLI!="")
                {
                  query=query+"UPPER(NOMCLI_CLI) like '%"+NOMCLI_CLI.ToUpper()+"%' and ";
                }
                  query = query.Remove(query.Length - 4).Trim() + " Order by NOMCLI_CLI asc";
                  return mod.consulta(query);
            } catch (Exception e) { throw e; }
        }
        #endregion

        #region  Propiedades tabla MAECLIP

        private string _CODCLI_CLI;
        public string CODCLI_CLI
        {
            get { return _CODCLI_CLI;}
            set { _CODCLI_CLI=value; RaisePropertyChangedEvent("CODCLI_CLI"); }
        }
        private string _NOMCLI_CLI;
        public string NOMCLI_CLI
        {
            get { return _NOMCLI_CLI;}
            set
            {
                if (_NOMCLI_CLI != value) { CAMBIO = true; } 
                _NOMCLI_CLI = value;
                RaisePropertyChangedEvent("NOMCLI_CLI");
            }
        }
        private string _NOMREP_CLI;
        public string NOMREP_CLI
        {
            get { return _NOMREP_CLI;}
            set
            {
                if (_NOMREP_CLI != value) { CAMBIO = true; }
                _NOMREP_CLI = value;
                RaisePropertyChangedEvent("NOMREP_CLI");
            }
        }
        private string _CONTAC_CLI;
        public string CONTAC_CLI
        {
            get { return _CONTAC_CLI;}
            set
            {
                if (_CONTAC_CLI != value) { CAMBIO = true; } 
                _CONTAC_CLI = value;
                RaisePropertyChangedEvent("CONTAC_CLI");
            }
        }
        private string _DIRCLI_CLI;
        public string DIRCLI_CLI
        {
            get { return _DIRCLI_CLI;}
            set
            {
                if (_DIRCLI_CLI != value) { CAMBIO = true; }
                _DIRCLI_CLI = value;
                RaisePropertyChangedEvent("DIRCLI_CLI");
            }
        }
        private string _CODCIU_CLI;
        public string CODCIU_CLI
        {
            get { return _CODCIU_CLI;}
            set
            {
                if (_CODCIU_CLI != value) { CAMBIO = true; }
                _CODCIU_CLI = value;
                RaisePropertyChangedEvent("CODCIU_CLI");
            }
        }
        private string _NITCLI_CLI;
        public string NITCLI_CLI
        {
            get { return _NITCLI_CLI;}
            set
            {
                if (_NITCLI_CLI != value) { CAMBIO = true; }
                _NITCLI_CLI = value;
                RaisePropertyChangedEvent("NITCLI_CLI");
            }
        }
        private string _TEL1CLI_CLI;
        public string TEL1CLI_CLI
        {
            get { return _TEL1CLI_CLI;}
            set
            {
                if (_TEL1CLI_CLI != value) { CAMBIO = true; }
                _TEL1CLI_CLI = value;
                RaisePropertyChangedEvent("TEL1CLI_CLI");
            }
        }
        private string _TEL2CLI_CLI;
        public string TEL2CLI_CLI
        {
            get { return _TEL2CLI_CLI;}
            set
            {
                if(_TEL2CLI_CLI != value) { CAMBIO = true; }
                _TEL2CLI_CLI = value;
                RaisePropertyChangedEvent("TEL2CLI_CLI");
            }
        }
        private string _FAXCLI_CLI;
        public string FAXCLI_CLI
        {
            get { return _FAXCLI_CLI;}
            set
            {
                if (_FAXCLI_CLI != value) { CAMBIO = true; }
                _FAXCLI_CLI = value;
                RaisePropertyChangedEvent("FAXCLI_CLI");
            }
        }
        private string _PLAZO_CLI;
        public string PLAZO_CLI
        {
            get { return _PLAZO_CLI;}
            set
            {
                if (_PLAZO_CLI != value) { CAMBIO = true; }
                _PLAZO_CLI = value;
                RaisePropertyChangedEvent("PLAZO_CLI");
            }
        }
        private string _APLRTE_CLI;
        public string APLRTE_CLI
        {
            get { return _APLRTE_CLI;}
            set
            {
                if (_APLRTE_CLI != value) { CAMBIO = true; }
                _APLRTE_CLI = value;
                RaisePropertyChangedEvent("APLRTE_CLI");
            }
        }

        private string _TIPO_CLI;
        public string TIPO_CLI
        {
            get { return _TIPO_CLI;}
            set
            {
                if (_TIPO_CLI != value) { CAMBIO = true; }
                _TIPO_CLI = value;
                RaisePropertyChangedEvent("TIPO_CLI");
            }
        }
        private string _CODLIS_CLI;
        public string CODLIS_CLI
        {
            get { return _CODLIS_CLI;}
            set
            {
                if (_CODLIS_CLI != value) { CAMBIO = true; }
                _CODLIS_CLI = value;
                RaisePropertyChangedEvent("CODLIS_CLI");
            }
        }
        private string _CODLISREP_CLI;
        public string CODLISREP_CLI
        {
            get { return _CODLISREP_CLI; }
            set
            {
                if (_CODLISREP_CLI != value) { CAMBIO = true; }
                _CODLISREP_CLI = value;
                RaisePropertyChangedEvent("CODLISREP_CLI");
            }
        }
        private string _EMAIL_CLI;
        public string EMAIL_CLI
        {
            get { return _EMAIL_CLI;}
            set
            {
                if (_EMAIL_CLI != value) { CAMBIO = true; }
                _EMAIL_CLI = value;
                RaisePropertyChangedEvent("EMAIL_CLI");
            }
        }
        private string _CLIPPAL_CLI;
        public string CLIPPAL_CLI
        {
            get { return _CLIPPAL_CLI;}
            set
            {
                if (_CLIPPAL_CLI != value) { CAMBIO = true; }
                _CLIPPAL_CLI = value;
                RaisePropertyChangedEvent("CLIPPAL_CLI");
            }
        }
        private string _ESTADO_CLI;
        public string ESTADO_CLI
        {
            get { return _ESTADO_CLI;}
            set
            {
                if (_ESTADO_CLI != value) { CAMBIO = true; }
                _ESTADO_CLI = value;
                RaisePropertyChangedEvent("ESTADO_CLI");
            }
        }
        private double _DCTCLI_CLI;
        public double DCTCLI_CLI
        {
            get { return _DCTCLI_CLI; }
            set 
            {
                if (_DCTCLI_CLI != value) { CAMBIO = true; }
                _DCTCLI_CLI = value; 
                RaisePropertyChangedEvent("DCTCLI_CLI"); 
            }
        }
        private string _CLICOM_CLI;
        public string CLICOM_CLI
        {
            get { return _CLICOM_CLI; }
            set
            {
                if (_CLICOM_CLI != value) { CAMBIO = true; }
                _CLICOM_CLI = value;
                RaisePropertyChangedEvent("CLICOM_CLI");
            }
        }
        private string _CLIINTERNO_CLI;
        public string CLIINTERNO_CLI
        {
            get { return _CLIINTERNO_CLI; }
            set
            {
                if (_CLIINTERNO_CLI != value) { CAMBIO = true; }
                _CLIINTERNO_CLI = value;
                RaisePropertyChangedEvent("CLIINTERNO_CLI");
            }
        }
        private Boolean _CAMBIO = false;
        public Boolean CAMBIO
        {
            get { return _CAMBIO; }
            set
            {
                _CAMBIO = value;
                RaisePropertyChangedEvent("CAMBIO");
            }
        }
        private Boolean _EXISTE = false;
        public Boolean EXISTE
        {
            get { return _EXISTE; }
            set
            {
                _EXISTE = value;
                RaisePropertyChangedEvent("EXISTE");
            }
        }

        #endregion
    }
}
